package cdu.sl.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactoryFriend;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")  // 填写/*表示拦截所有路径
public class DemoFilter implements Filter {
    public static final Logger log = LoggerFactory.getLogger(DemoFilter.class);

    // 初始化方法 , web服务器启动的时候执行 , 只会执行一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("init 初始化方法...");
    }

    // 业务方法 , 拦截到请求之后执行 , 会执行多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("拦截到请求,{}",servletRequest.getParameter("username"));
        // 放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        log.info("destroy销毁方法.....");
    }

}
